package jbpmguice.workflow;

import com.google.inject.Inject;
import jbpmguice.business.InjectableIf;
import org.jbpm.graph.def.ActionHandler;
import org.jbpm.graph.exe.ExecutionContext;

import javax.inject.Singleton;
import java.util.logging.Logger;


@Singleton
public class InjectableTestAction implements ActionHandler {

    private static final long serialVersionUID = -4373219385070096215L;

    InjectableIf inj;

    private String beanProperty;

    int executionCounter;

    Logger log = Logger.getLogger(InjectableTestAction.class.getName());

    @Inject
    public InjectableTestAction(InjectableIf inj) {
        this.inj = inj;
    }

    public int getExecutionCounter() {
        return executionCounter;
    }

    public void execute(ExecutionContext executionContext) throws Exception {
        executionCounter++;
        this.inj.helloWorld();
        log.info(String.format("Executed Dummy Step. Counting Singleton Invocation [%d]", executionCounter));
    }

    public void setBeanProperty(String beanProperty) {
        this.beanProperty = beanProperty;
    }

    public String getBeanProperty() {
        return beanProperty;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("jbpmguice.workflow.InjectableTestAction");
        sb.append("{counter=").append(executionCounter);
        sb.append('}');
        return sb.toString();
    }
}
